﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WpfLussen
{
	/// <summary>
	/// Interaction logic for Faculteit.xaml
	/// </summary>
	public partial class Faculteit : Window
	{
		public Faculteit()
		{
			InitializeComponent();
		}

		private void btnBerekenFaculteit_Click(object sender, RoutedEventArgs e)
		{
			int getal = int.Parse(txtGetal.Text);
			long resultaat = BerekenFaculteitRecursief(getal);
			lblFaculteit.Content = resultaat.ToString();
		}

		private long BerekenFaculteit(int getal)
		{
			long faculteit = 1;
			while (getal > 1)
			{
				faculteit *= getal;
				getal--;
			}
			return faculteit;
		}

		//Extra: recursie
		private long BerekenFaculteitRecursief(int getal)
		{
			long faculteit = 1;
			if (getal > 1)
			{
				faculteit = getal * BerekenFaculteitRecursief(getal - 1);
			}

			return faculteit;
		}
	}
}
